package ve.com.wayoyo.wuml_case.DibujoDiagramas;

import android.graphics.Point;

public class BorderAnchors {
	

	private int _numOfDiv;
	private int[] _costOfAnchorPoints;
	private Point[] _anchorPoint;
	
	public BorderAnchors(int numOfDivs,Point start,Point end){
		int spaceDivX  = (end.x - start.x)/numOfDivs+2;
		int spaceDivY  = (end.y - start.y)/numOfDivs+2;
		_numOfDiv = numOfDivs;
		_anchorPoint = new Point[_numOfDiv];
		_costOfAnchorPoints = new int[_numOfDiv];
		for (int i = 0; i < _numOfDiv; i++) {
			_costOfAnchorPoints[i] = 0;
			_anchorPoint[i] = new Point(start.x + ((i+1)*spaceDivX),start.y + ((i+1)*spaceDivY));
		}
	}
	
	public void actualizar(Point start,Point end){
		int spaceDivX  = (end.x - start.x)/_numOfDiv+1 ;
		int spaceDivY  = (end.y - start.y)/_numOfDiv+1 ;
		for (int i = 0; i < _numOfDiv; i++) {
			_anchorPoint[i].set(start.x + ((i+1)*spaceDivX), start.y + ((i+1)*spaceDivY));
		}
	}
	
	public Point obtenerPosicion(){
		int lessCost= Integer.MAX_VALUE;
		int lessCostIndex = 0;
		for (int i = 0; i < _numOfDiv; i++) {
			if(_costOfAnchorPoints[i] < lessCost){
				lessCostIndex = i;
				lessCost = _costOfAnchorPoints[i];
			}
		}
		_costOfAnchorPoints[lessCostIndex]++;
		return _anchorPoint[lessCostIndex];
	}

}
